package com.jzj.servlet;

import com.jzj.Dao.impl.All;
import com.jzj.entity.Movie;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/add")
public class indexServlet extends HttpServlet {

//    @Override
//    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
//        req.setCharacterEncoding("UTF-8");
//        String name=req.getParameter("name");
//        String actor=req.getParameter("actor");
//        String dirctor=req.getParameter("dirctor");
//        String movie_time=req.getParameter("movie_time");
//        String type=req.getParameter("type");
//        All all = new All();
//        if (all.Selectname(name)){
//            req.setAttribute("msg","该电影已添加");
//            req.getRequestDispatcher("/jsp/add.jsp").forward(req,res);
//        }else {
//            Movie movie = new Movie(name,actor,dirctor,Integer.valueOf(movie_time),type);
//            all.addSQL(movie);
//            req.getRequestDispatcher("/jsp/index.jsp").forward(req,res);
//        }
//
//
//    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String name = req.getParameter("name");
        String actor = req.getParameter("actor");
        String dirctor = req.getParameter("dirctor");
        String movie_time = req.getParameter("movie_time");
        String type = req.getParameter("type");
        All all = new All();
        if (all.Selectname(name)) {
            req.setAttribute("msg", "该电影已添加");
            req.getRequestDispatcher("jsp/add.jsp").forward(req,resp);
            resp.sendRedirect("/test2/jsp/add.jsp");
        } else {
            Movie movie = new Movie(name, actor, dirctor, Integer.valueOf(movie_time), type);
            all.addSQL(movie);
            resp.sendRedirect("/test2/jsp/index.jsp");
        }
    }




}
